package com.zh.Service;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.Tables;
import lombok.SneakyThrows;
import org.ddr.poi.html.HtmlRenderPolicy;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WriteWord {

    @SneakyThrows
    public static void main(String[] args) {
        String filePath1=    "E://test.docx";
        String filePath2 = "E://test2.docx";
        File file = new File("E://test.docx");
        InputStream inputStream = new FileInputStream(file);
        HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
        Configure configure = Configure.builder()
                // 注册html解析插件
                .bind("content", htmlRenderPolicy)
                .build();


        XWPFTemplate template = XWPFTemplate.compile(inputStream,configure).render(new HashMap<String, Object>() {{
            //表格上部分
            put("fbdw","发布单位"); //发布单位
            put("kbmc", "快报名称"); //快报名称
            put("qh", "期号");     //期号
            List<Map<String, Object>> contentsList = new ArrayList<>();
            for (int i = 0; i < 10 ; i++) {
                Map<String, Object> childmap = new HashMap<>();
                //childmap.
            }
//            Tables.create(rowRenderData);
//            put("list", new );
        }});


        try {
            template.writeAndClose(new FileOutputStream(filePath1));
            inputStream.close();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }

    }
}
